<?php
namespace Business;
class CategoryModel{
    static public function getAll($parent_id = null){
        $user = \CategoryModel::get();
        if ($user) {
            $data = $user->toArray();
        } else {
            $data = array();
        }
        return $data;
    }
    static public function getList($parent_id = null){
        $user = \CategoryModel::get();
        if ($user) {
            $data = $user->toArray();
        } else {
            $data = array();
        }
        return $data;
    }
    static public function getTree($parent_id = null){
        $data = static::getAll();
        $tree = \Tools::list_to_tree($data, $pk = 'category_id', $pid = 'parent_id', $child = 'sub', $root = $parent_id);
        return $tree;
    }
    static public function getParents($id) {
        $data = static::getAll();
        $tree = \Tools::tree_parents($data, $id,'category_id','parent_id');
        return $tree;
    }
    static public function getLatest($limit =10){
        $user = \CategoryLatestModel::join('category','category_latest.category_id','=','category.category_id')->take($limit)->get();
        if ($user) {
            $data = $user->toArray();
        } else {
            $data = array();
        }
        return $data;
    }
}
